// pages/dianpu/daixiaodianpu/daixiaodianpu.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dingdanid: '',
    resshopid: '',
    shopBean: '',
    orderBean: '',
    // orderBeans:'',
    appGoodsManger: [],
    beans: '',
    type: ''
  },
  // 资质预览
  preview() {
    var imglist = this.data.shopBean.licenses
    wx.previewImage({
      urls: imglist
    })
  },
  // 去商品详情
  togoodsxq(e) {
    let that = this
    let goodsid = e.currentTarget.dataset.goodsid
    wx.navigateTo({
      url: '/pages/goods/page/goodsXiangqing/daixiaoxianshiGoods/daixiaoxianshiGoods?goodsid=' + goodsid,
    })
  },
  // 拨打电话
  dialphone() {
    let that = this
    wx.makePhoneCall({
      phoneNumber: that.data.shopBean.shopPhone
    })
  },
  // 获取本页所有信息
  getRetailSales() {
    let that = this
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "getRetailSales",
        shopId: wx.getStorageSync('shopId'),
        userId: wx.getStorageSync('userId'),
        reshopId: that.data.resshopid,
        reId: that.data.dingdanid
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        console.log(res)
        if (res.data.result == 1) {
          setTimeout(function() {
            wx.hideLoading()
          }, 0)
          setTimeout(function() {
            wx.showToast({
              title: res.data.resultNote,
              icon: 'none',
              duration: 1500
            })
          }, 0)
        } else {
          that.setData({
            shopBean: res.data.shopBean,
            orderBean: res.data.bean,
            // orderBeans: res.data.orderBeans,
            appGoodsManger: res.data.appGoodsManger,
            beans: res.data.beansOrder,
          })
          let orderBean = res.data.bean
          let daixiaojsm = (new Date(orderBean.actBean.endTtime.replace(/-/g, '/'))).getMonth() + 1
          let daixiaojsd = (new Date(orderBean.actBean.endTtime.replace(/-/g, '/'))).getDate()
          orderBean.actBean.endstr = daixiaojsm + '月' + daixiaojsd + '日' + (orderBean.actBean.endTtime).substring(10, 16)

          let lingshoujsm = (new Date(orderBean.actBean.saleeTime.replace(/-/g, '/'))).getMonth() + 1
          let lingshoujsy = (new Date(orderBean.actBean.saleeTime.replace(/-/g, '/'))).getDate()
          orderBean.actBean.saleestr = lingshoujsm + '月' + lingshoujsy + '日' + (orderBean.actBean.saleeTime).substring(10, 16)

          let jiesuanjsm = (new Date(orderBean.actBean.accteTime.replace(/-/g, '/'))).getMonth() + 1
          let jiesuanjsy = (new Date(orderBean.actBean.accteTime.replace(/-/g, '/'))).getDate()
          orderBean.actBean.acctestr = jiesuanjsm + '月' + jiesuanjsy + '日' + (orderBean.actBean.accteTime).substring(10, 16)
          that.setData({
            orderBean: orderBean
          })
          setTimeout(function() {
            wx.hideLoading()
          }, 0)
        }
      }
    });
  },
  // 查看零售订单
  todianpuDingdan() {
    let that = this
    wx.navigateTo({
      url: '/pages/order/page/lingshouDingdan/dianpunei/dianpunei?dingdanid=' + that.data.dingdanid + '&resshopid=' + that.data.resshopid + '&regoodsId=' + that.data.beans[0].goodsList[0].goodsId,
    })
  },
  // 查看更多评价
  tomorePingjia() {
    let that = this
    wx.navigateTo({
      url: '/pages/setting/page/dianpu/dianpupingjia/dianpupingjia?regoodsId=' + that.data.beans[0].goodsList[0].goodsId + '&resshopid=' + that.data.resshopid
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    this.setData({
      dingdanid: options.dingdanid,
      resshopid: options.resshopid,
      type: options.type,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this
    setTimeout(function() {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    that.getRetailSales()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})